import { Ref } from 'vue';
import { BasicColumn, FormSchema } from '/@/components/Table';
import { useI18n } from '/@/hooks/web/useI18n';
import { ActionEnum } from '/@/enums/commonEnum';
import { FormSchemaExt, RuleType } from '/@/api/lamp/common/formValidateService';
import { check } from '/@/api/devOperation/system/defDict';
import { stateFilters, stateComponentProps } from '/@/utils/lamp/common';
import { query as queryTenant } from '/@/api/devOperation/tenant/tenant';
import { TenantStatusEnum } from '/@/enums/biz/tenant';
import { getAllTaskNegativeItemYears } from '/@/api/basic/qimo/index';
const { t } = useI18n();
// 列表页字段
export const columns = (): BasicColumn[] => {
  return [
    {
      title: '学院',
      dataIndex: 'itemTenantName',
    },
    {
      title: '类型',
      dataIndex: 'itemTypeName',
    },
    {
      title: '内容',
      dataIndex: 'involveUserNames',
      width: 100,
      // filters: [...stateFilters()],
    },
    {
      title: '核减分数',
      dataIndex: 'cutScore',
      sorter: true,
      // width: 180,
    },
  ];
};

export const searchFormSchema = (): FormSchema[] => {
  return [
    {
      label: '年份',
      field: 'year',
      // component: 'ApiSelect',
      component: 'Select',
      colProps: { span: 12 },
      defaultValue: new Date().getFullYear(),
      componentProps: {
        options: Array.from({ length: 21 }, (_, index) => ({
          label: 2023 + index + '',
          value: 2023 + index,
        })),
        // api: getAllTaskNegativeItemYears,
        // labelField: 'lable',
        // valueField: 'year',
        // showSearch: true,
      },
    },
  ];
};

// 编辑页字段
export const editFormSchema = (): FormSchema[] => {
  return [
    {
      field: 'id',
      component: 'Input',
      label: 'ID',
      show: false,
    },
    {
      label: '年份',
      field: 'year',
      component: 'Select',
      componentProps: {
        options: Array.from({ length: 21 }, (_, index) => ({
          label: 2023 + index + '',
          value: 2023 + index,
        })),
        // defaultValue: 2023,  // 如果需要设置默认值为2023，可以取消注释这行
      },
    },
    {
      label: '请选择部门',
      field: 'itemTenantId',
      // component: 'ApiSelect',
      component: 'Select',
      // componentProps: ({ tableAction }) => {
      //   return {
      //     api: queryTenant,
      //     labelField: 'name',
      //     valueField: 'id',
      //     params: {
      //       status: TenantStatusEnum.NORMAL,
      //     },
      //     showSearch: true,
      //     filterOption: (input: string, option: any) => {
      //       return option.label.toUpperCase().indexOf(input.toUpperCase()) >= 0;
      //     },
      //     onChange: (value) => {
      //       const { reload } = tableAction;
      //       reload({ searchInfo: { itemTenantId: value } });
      //     },
      //   };
      // },
      componentProps: {
        options: [
          { value: '520154675945986049', label: '计算机与信息技术学院', key: '1' },
          { value: '520154675945986052', label: '商学院', key: '2' },
          { value: '520154675945986055', label: '教务处', key: '3' },
          { value: '526891104516526724', label: '智能制造技术学院', key: '4' },
          { value: '526891104516526727', label: '仲景中医药与健康学院', key: '5' },
          { value: '526891104516526732', label: '教育学院', key: '6' },
          { value: '526891104516526749', label: '建筑与艺术设计学院', key: '7' },
          { value: '526891104516526752', label: '体育学院', key: '8' },
          { value: '526891104516526755', label: '中专部', key: '9' },
          { value: '526891104516526758', label: '公共教学部', key: '10' },
          { value: '526891104516526761', label: '马克思主义学院', key: '11' },
          { value: '526891104516526764', label: '继续教育学院', key: '12' },
          { value: '526891104516526767', label: '党群工作部', key: '13' },
          { value: '526891104516526770', label: '党政办公室', key: '14' },
          { value: '526891104516526774', label: '发展规划处（创新创业学院）', key: '15' },
          { value: '526891104516526777', label: '人力资源部', key: '16' },
          { value: '526891104516526780', label: '科技外事处', key: '17' },
          { value: '526891104516526783', label: '学生工作处', key: '18' },
          { value: '526891104516526786', label: '法务监督部', key: '19' },
          { value: '526891104516526789', label: '招生工作办公室', key: '20' },
          {
            value: '526891104516526796',
            label: '大学生实习实训与就业指导中心（校地合作处）',
            key: '21',
          },
          { value: '526891104516526799', label: '财务处', key: '22' },
          { value: '526891104516526802', label: '基建处', key: '23' },
          { value: '526891104516526805', label: '保卫处', key: '24' },
          { value: '526891104516526808', label: '后勤管理处', key: '25' },
          { value: '526891104516526813', label: '心理健康教育中心', key: '26' },
          { value: '526891104516526823', label: '图书馆', key: '27' },
          { value: '526891104516526831', label: '后勤服务集团直属党支部', key: '28' },
        ],
      },
    },
    {
      label: '类型',
      field: 'itemType',
      component: 'Select',
      required: true,
      componentProps: {
        options: [
          { value: 'A', label: '负面清单', key: '1' },
          { value: 'B', label: '一票否决', key: '2' },
        ],
      },
    },
    {
      label: '涉及人员',
      field: 'involveUserNames',
      component: 'Input',
      required: true,
      // componentProps: {
      //   ...stateComponentProps(),
      // },
      // defaultValue: true,
    },
    {
      label: '核减分数',
      field: 'cutScore',
      component: 'Input',
      rules: [
        { required: true, message: '请输入核减分数' },
        {
          pattern: /^-?\d+(\.\d{1,2})?$/,
          message: '请输入合法数字，保留小数点后两位',
        },
      ],
      // rules: [
      //   { required: true, message: '请输入核减分数' },
      //   { pattern: /^\d+(.\d{1,2})?$/, message: '请输入合法数字，保留小数点后两位' },
      // ],
    },
  ];
};

// 前端自定义表单验证规则
